from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django import http
import MySQLdb
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
# 声明全局使用的游标对象， 用于数据库查询
from cake_shop import db
cursor = db.my_connection.cursor()


@require_http_methods(["POST", "GET"])
@csrf_exempt
def cake_all(request):
    cursor.execute("select * from tb_cake")
    datas = cursor.fetchall()
    # for data in datas:
    #     print(data)
    # ds = json.dumps(data, ensure_ascii=False)
    return JsonResponse(datas, safe=False)
